package com.example.testrecorder;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;

import com.example.testrecorder.adapter.QueAndAnsAdapter;
import com.example.testrecorder.adapter.UserAdapter;
import com.example.testrecorder.domain.QueAndAns;
import com.example.testrecorder.domain.User;
import com.example.testrecorder.view.NoScrollListView;

import org.litepal.LitePal;

import java.util.List;

public class ViewTableActivity extends BaseActivity {
    private Toolbar toolbar;
    private NoScrollListView lv;
    private static final String TAG = "ViewTableActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_table);
        initView();
    }

    private void initView() {
        lv=findViewById(R.id.lv);
        toolbar=findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Intent intent = getIntent();
        String pa = intent.getStringExtra("pa");
        if(!TextUtils.isEmpty(pa)){
            if(pa.equals("userTabel")){
                toolbar.setTitle("用户表");
                List<User> all = LitePal.findAll(User.class);
                lv.setAdapter(new UserAdapter(all));
            }else if(pa.equals("qaTabel")){
                toolbar.setTitle("密保表");
                List<QueAndAns> all = LitePal.findAll(QueAndAns.class);
                lv.setAdapter(new QueAndAnsAdapter(all));
            }
        }
    }
}